package code.structure.module.user
{
	import code.main.AppCommonData;
	import code.main.AppCommonView;
	import code.main.AppData;
	import code.main.core.mvc.YController;
	import code.structure.module.user.view.UserView;
	import code.tools.traceLog.TraceLog;
	import code.untils.CommandNameConst;
	import code.untils.GameSettingConfig;
	import code.untils.RandomMath;
	
	import com.patience.mvc.context.Command;
	
	/**
	 *用户信息控制器
	 * @author Yuri
	 *
	 */
	public class UserController extends YController
	{
		//数据
		private var _userModle:UserModel;
		private var _userView:UserView;
		public function UserController()
		{
			super();
			
		}
		
		override public function start():void
		{
			TraceLog.showTrace("用户信息模块程序启动")
			_userView = new UserView((_context.commonView as AppCommonView).appContainer.uiLayer);
				
			_userModle = new UserModel();
			(_context.commonData as AppCommonData).userModel = _userModle;
			RandomMath.userModel = _userModle;
			initRegisters();
		}
		
		/**
		 *注册侦听
		 *
		 */
		private function initRegisters():void
		{
			register(CommandNameConst.COMMAND_USERDATA_ANALY_COMPLETE,onCommandHandler);
			register(CommandNameConst.COMMAND_UPDATE_LEVEL, onCommandHandler);
			register(CommandNameConst.COMMAND_UPDATE_COIN, onCommandHandler);
		}
		
		//各命令解析并执行相应操作
		private function onCommandHandler(c:Command):void
		{
			const d:uint = c.data as uint;
			switch (c.cmdName)
			{
				case CommandNameConst.COMMAND_ANALYSIS_MAP_COMPLETE: 
					GameSettingConfig.isCanWheel = !AppData.isNew;
					break;
				case CommandNameConst.COMMAND_UPDATE_LEVEL:
					_userView.updateLevel(int(c.data));
					break;
				case CommandNameConst.COMMAND_UPDATE_COIN:
					_userView.updateCoin(d);
					break;
			}
		}
		
		public function get userModle():UserModel
		{
			return _userModle;
		}
	}
}